package com.sebiotec.ambassador.adapt;

import android.view.View;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseDelegateMultiAdapter;
import com.chad.library.adapter.base.delegate.BaseMultiTypeDelegate;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sebiotec.ambassador.R;
import com.sebiotec.ambassador.model.SearchEntrty;


import java.util.List;

public class HistoryAdapt extends BaseDelegateMultiAdapter<SearchEntrty.RowsBean, BaseViewHolder> {

    public HistoryAdapt() {
            super();

        setMultiTypeDelegate(new BaseMultiTypeDelegate<SearchEntrty.RowsBean>() {
            @Override
            public int getItemType(@NonNull List<? extends SearchEntrty.RowsBean> data, int position) {
                // 根据数据，自己判断应该返回的类型


                    switch (data.get(position).getStatus()) {
                        case -1:
                            return 1;
                        case -2:
                            return 3;
                        case 0:
                            return 2;
                        case 1:
                            return 0;
                        case 2:
                            return 0;
                        case 3:
                            return 0;
                        case 4:
                            return 0;
                        case 5:
                            return 3;
                        default:
                            return  0;

                    }




            }
        });
        // 第二部，绑定 item 类型
        getMultiTypeDelegate()
                .addItemType(0, R.layout.item_history1)//金色
                .addItemType(1, R.layout.item_history2)//红色
                .addItemType(2, R.layout.item_history3)//黑色
                .addItemType(3, R.layout.item_history4);//灰色
    }

    @Override
    protected void convert(BaseViewHolder helper, SearchEntrty.RowsBean item) {

        helper.setText(R.id.tv_upcoming_name, item.getName());
        helper.setText(R.id.tv_num, item.getPassengers() + "");


        if ("".equals(item.getServesUser())){

            helper.itemView.findViewById(R.id.ll_dx).setVisibility(View.GONE);
        }
        switch (item.getStatus()) {
            //1:Ambassador pickup 2:Driver pickup 3: Completed(Driver pickdown) 4:Rejected
            case 1:
                helper.setText(R.id.tv_titles,"Confirmed by"+" "+item.getServesUser());
                break;
            case 2:
                helper.setText(R.id.tv_titles, "Picked-up by"+" "+item.getServesUser());
                break;
            case 3:
                helper.setText(R.id.tv_titles, "Picked-up by"+" "+item.getServesUser());
                break;
            case 4:
                helper.setText(R.id.tv_titles, "Droped-off by"+" "+item.getServesUser());
                break;
            case 5:
                helper.setText(R.id.tv_titles, "Completed by"+" "+item.getServesUser());
                break;
            case 6:
                helper.setText(R.id.tv_titles, "Assigned vehicle by"+" "+item.getServesUser());
                break;
            case 7:
                helper.setText(R.id.tv_titles, "Assigned driver by"+" "+item.getServesUser());
                break;
            case 8:
                helper.setText(R.id.tv_titles, "Assigned ambassador by"+" "+item.getServesUser());
                break;
            case -2:
                helper.setText(R.id.tv_titles, "Cancelled by"+" "+item.getServesUser());
                break;
            case -1:
                helper.setText(R.id.tv_titles, "Rejected by"+" "+item.getServesUser());
                break;

            default:
                helper.setText(R.id.tv_titles, "Ambassador by"+" "+item.getServesUser());
                break;
        }

        helper.setText(R.id.tv_address, item.getPickupFrom());
        helper.setText(R.id.tv_pickup_time,item.getPickupDateTime());
        helper.setText(R.id.tv_to_address, item.getDestination());
        helper.setText(R.id.tv_recevied_by,item.getServesDateTime());


    }
}